﻿using IncidentesBE;
using IncidentesBL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IncidentesWEB.admin
{
    public partial class RegistrarPlanInmediato : System.Web.UI.Page
    {
        Fnc_FuncionariosBL _Fnc_FuncionariosBL = new Fnc_FuncionariosBL();
        TB_PlanAccionBL _TB_PlanAccionBL = new TB_PlanAccionBL();

        TB_PlanAccionBE _TB_PlanAccionBE = new TB_PlanAccionBE();

        List<Fnc_FuncionariosBE> lTFnc_FuncionariosBE;

        int _Incidente_id;
        string fecha_actual;

        protected void Page_Load(object sender, EventArgs e)
        {
            _Incidente_id = Convert.ToInt32(Request.QueryString["Incidente_id"]);
            if (this.IsPostBack)
            {

            }
            else
            {
                _Incidente_id = Convert.ToInt32(Request.QueryString["Incidente_id"]);
                DateTime Hoy = DateTime.Today;
                fecha_actual = Hoy.ToString("dd/MM/yyyy");
                txtFecha.Text = fecha_actual;
                LlenarComboResponsable();
                ddlResponsable.SelectedValue = ((Fnc_FuncionariosBE)Session["Fnc_Funcionarios"]).Funcionario_Id.ToString();
            }
        }

        private void LlenarComboResponsable()
        {
            lTFnc_FuncionariosBE = _Fnc_FuncionariosBL.ListarFnc_FuncionariosO_Act();
            ddlResponsable.DataSource = lTFnc_FuncionariosBE;
            ddlResponsable.DataValueField = "Funcionario_id";
            ddlResponsable.DataTextField = "Funcionario_nome";
            ddlResponsable.DataBind();
        }

        protected void btnRegistrar_Click(object sender, EventArgs e)
        {
            _TB_PlanAccionBE.Fecha = DateTime.ParseExact(txtFecha.Text, "dd/MM/yyyy", null);
            _TB_PlanAccionBE.Registro_id = _Incidente_id;
            _TB_PlanAccionBE.PlanAccion_desc = txtPlan.Text;
            _TB_PlanAccionBE.Responsable = Convert.ToInt32(ddlResponsable.SelectedValue);
            _TB_PlanAccionBE.Estado = chbCumplido.Checked;
            if(_TB_PlanAccionBL.InsertarTB_PlanAccion(_TB_PlanAccionBE))
                ClientScript.RegisterStartupScript(this.GetType(), "myScript", "ActualizoExito();cerrarYActualizar();", true);
            else
                Response.Write("<script language=javascript>alert('ERROR');</script>");
        }
    }
}